package com.cspg.ssss.vo.convert;


import com.cspg.ssss.domain.CompanyRectifyViewEntity;
import com.cspg.ssss.domain.UserDetailInfoEntity;
import com.cspg.ssss.util.DateUtil;
import com.cspg.ssss.vo.CompanyRectifyViewVo;
import com.cspg.ssss.vo.UserInfoVo;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CompanyRectifyViewVoConvert {
    public static CompanyRectifyViewVo ConvertFromViewEntity(CompanyRectifyViewEntity en) {
        CompanyRectifyViewVo vo = new CompanyRectifyViewVo();
        vo.setId(en.getId());
        vo.setDepartment_name(en.getDepartment_name());
        vo.setPerson_name(en.getPerson_name());
        vo.setInstance_title(en.getInstance_title());
        vo.setCreatea_time(en.getCreatea_time());
        vo.setIsover(en.getIsover());
        vo.setDatafrom(en.getDatafrom());
        vo.setDytxdy(en.getDytxdy());
        vo.setDytxys(en.getDytxys());
        vo.setGlhj(en.getGlhj());
        vo.setSfzdbl(en.getSfzdbl());
        vo.setSfslwt(en.getSfslwt());
        vo.setZylb(en.getZylb());
        vo.setKhbm(en.getKhbm());
        vo.setBmmc(en.getBmmc());
        vo.setWtlb(en.getWtlb());
        vo.setWtms(en.getWtms());
        vo.setXh(en.getXh());
        vo.setDwmc(en.getDwmc());
        vo.setSscm(en.getSscm());
        vo.setWtfxr(en.getWtfxr());
        vo.setGbyy(en.getGbyy());
        vo.setWtfxsj(en.getWtfxsj());
        vo.setYwsx(en.getYwsx());
        vo.setWtyzcd(en.getWtyzcd());
        vo.setZgjy(en.getZgjy());
        vo.setWtfxfs(en.getWtfxfs());
        vo.setProblem_id(en.getProblem_id());
        vo.setDuty_dept(en.getDuty_dept());

        if (en.getComplete_date() != null) {
            vo.setDuty_date(new SimpleDateFormat("yyyy-MM-dd").format(en.getDuty_date()));
        }

        vo.setRectify_content(en.getRectify_content());
        if(en.getRectify_deadline() != null){
            vo.setRectify_deadline(new SimpleDateFormat("yyyy-MM-dd").format(en.getRectify_deadline()));
        }

        vo.setRectify_commit(en.getRectify_commit());

        if(en.getRectify_commit_date() != null){
            vo.setRectify_commit_date(new SimpleDateFormat("yyyy-MM-dd").format(en.getRectify_commit_date()));
        }

        if(en.getComplete_date() != null){
            vo.setComplete_date(new SimpleDateFormat("yyyy-MM-dd").format(en.getComplete_date()));
        }


        if(en.getRectify_status() == null || en.getRectify_status().equals("")){
            vo.setRectify_status("unprocess");
        }else {
            vo.setRectify_status(en.getRectify_status());
        }

        vo.setProblem_type(en.getProblem_type());

        if (en.getRectify_status() != null && en.getRectify_status().equals("duty") && DateUtil.workDaysPeriod(en.getDuty_date(), new Date()) > 5) {
            vo.setPlanoutdate(true);
        } else {
            vo.setPlanoutdate(false);
        }

        Date judgeDate = new Date();
        if (en.getComplete_date() != null) {
            judgeDate = en.getComplete_date();
        }

        vo.setRectifyoutdate(false);
        if (en.getRectify_deadline() != null && judgeDate.compareTo(en.getRectify_deadline()) > 0) {
            vo.setRectifyoutdate(true);
        }


        return vo;
    }

    public static List<CompanyRectifyViewVo> ConvertList(List<CompanyRectifyViewEntity> enList) {
        List<CompanyRectifyViewVo> retList = new ArrayList<CompanyRectifyViewVo>();
        for (CompanyRectifyViewEntity en : enList) {
            CompanyRectifyViewVo vo = new CompanyRectifyViewVo();
            vo = ConvertFromViewEntity(en);
            retList.add(vo);
        }
        return retList;
    }
}
